package com.psc.view.customized;


import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.psc.R;
import com.psc.view.utils.glide.GlideUtils;

import java.util.List;

/**
 * Creator:Yx   Time:2020/7/30 10:29
 * Description:图文卡片 上图下文，图片上面两个倒角，下面平
 */
public class ImageTextView extends LinearLayout {

    public ImageTextView(Context context) {
        super(context);
    }

    public ImageTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setOrientation(HORIZONTAL);
        setGravity(Gravity.CENTER_VERTICAL);
        LayoutInflater inflater = LayoutInflater.from(context);
        for (int i = 0; i < 4; i++) {
            LinearLayout item = (LinearLayout) inflater.inflate(R.layout.item_public_card_2, this, false);
            TextView titleView = item.findViewById(R.id.item_public_car2title);
            TextView numView = item.findViewById(R.id.item_public_car2num);
            ImageView img = item.findViewById(R.id.item_public_car2img);
            GlideUtils.setImages("https://04imgmini.eastday.com/mobile/20200710/20200710001045_4169179853bedfc4ea719c0fc81a7fcf_1.jpeg"
                    , img);
            addView(item);
        }
    }

    public void setDatas(List<String> mLists) {
        if (mLists != null && mLists.size() > 0) {
            for (int i = 0; i < mLists.size(); i++) {
                LinearLayout item = (LinearLayout) this.getChildAt(i);
                TextView titleView = item.findViewById(R.id.item_public_car2title);
                TextView numView = item.findViewById(R.id.item_public_car2num);
                ImageView img = item.findViewById(R.id.item_public_car2img);
                titleView.setText(mLists.get(i));
                numView.setText("top50");
                GlideUtils.setImages("https://04imgmini.eastday.com/mobile/20200710/20200710001045_4169179853bedfc4ea719c0fc81a7fcf_1.jpeg"
                        , img);
                //img.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.icon_gougg));
            }

        }
    }

    private int dpToPx(int dp) {
        float scale = Resources.getSystem().getDisplayMetrics().density;
        return (int) (dp * scale + 0.5f);
    }


}
